<template>
    <a-modal 
    class="my-modal short" 
    v-model:visible="modal_show" 
    title="新建文件夹" 
    @ok="modelok" 
    width="400px" 
    :maskClosable="false" 
    :centered="true"
    :destroyOnClose="true"
    >
        <div class="body-content">
            <a-input size="small" placeholder="" v-model:value="options.dir_name" />
        </div>
    </a-modal>
</template>
<script>
export default {
    components: {},
    data() {
        return {
            modal_show: false,
            options:{
                dir_name: '',
                pre_dir: '',
            },

            //
            mitt_mk_new_dir_id:"",
            mitt_mk_new_dir_back_id:"",
        };
    },
    beforeUnmount() {
        this.$mitt.off('mk_new_dir', this.mitt_mk_new_dir_id);
    },
    mounted() { 
        this.mitt_mk_new_dir_id=this.$mitt.on('mk_new_dir', this.mk_new_dir_fn);
    },
    methods: {
        mk_new_dir_fn(uid,_options ){
            this.mitt_mk_new_dir_back_id=uid
            this.options.dir_name = '';
            this.options = Object.assign({}, {
                pre_dir: '',
            }, _options);
            this.modal_show = true;
        },

        async modelok() {
            const reg = new RegExp('[\\\\/:*?"<>|]');
            if (reg.test(this.options?.dir_name)) {
                this.$message.info('不能包含【\\\\/:*?"<>|】这些非法字符,请修改!');
                return;
            }
            let mk_result=await this.$apis.mk_dir({
                ph: `${this.options?.pre_dir}/${this.options?.dir_name}`.replace('//', '/'),
            })
            if (mk_result?.status) {
                this.modal_show = false;
                this.$message.success("创建文件夹成功")
                this.$mitt.oemit('mk_new_dir_back',"",this?.mitt_mk_new_dir_back_id);
            }
            else{
                this.$message.info(mk_result?.message)
            }
        },
    },
};
</script>